package com.hspedu.threaduse;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/15
 * @time 12:48
 */
public class Thread03 {
    public static void main(String[] args) {
        T1 t1 = new T1();
        Thread thread1 = new Thread(t1);
        thread1.start();
        Thread thread = new Thread(t1);
        thread.start();

        T2 t2 = new T2();
        Thread thread2 = new Thread(t2);
        thread2.start();
    }
}

class T1 implements Runnable{
    @Override
    public void run() {
        int num = 0;
        while (true){
            System.out.println("hello world! "+ (++num));
            if (num == 10)
                break;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

class T2 implements Runnable{
    @Override
    public void run() {
        int num = 0;
        while (true){
            System.out.println("hi "+ (++num));
            if (num == 5)
                break;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

